<template>
	<div class="pages">
		<!-- 头部导航 -->
		<div class="header animate__fadeInDown">
			<button class="back-button fff" @click="router.back()">
				<span class="back-icon">←</span>
			</button>
			<span class="header-title fff">配置DeepSeek</span>
		</div>
    <div class="set-page">
      <div class="set-page-title animate__fadeInDown">
        <div class="left">输入配置</div>
        <div class="right decoration">
          <a href="https://www.volcengine.com/">如何获取？</a>
        </div>
      </div>
      <div class="set-page-items animate__fadeInDown">
        <div class="title">
          <div class="require">*</div>
          <div class="text">BaseUrl</div>
        </div>
        <input type="text" v-model="store.userConfig.dsBaseUrl" disabled placeholder="请输入"/>
      </div>
      <div class="set-page-items animate__fadeInDown">
        <div class="title">
          <div class="require">*</div>
          <div class="text">ARK_API_KEY</div>
        </div>
        <input type="text" v-model="store.userConfig.dsApiKey" placeholder="请输入"/>
      </div>
      <div class="set-page-items animate__fadeInDown">
        <div class="title">
          <div class="require">*</div>
          <div class="text">model</div>
        </div>
        <input type="text" v-model="store.userConfig.dsModel" placeholder="请输入"/>
      </div>
      <div style="height: 106px"></div>
      <div class="button-block animate__fadeInUp">
        <!-- <button @click="resetDeepseek">重置</button> -->
        <button @click="userUpdate">确定</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from '@/stores/data'
import { dialog } from '@/utils/dialog'
const store = useStore();

const router = useRouter()

const showToast = ref(false)
const toastConfig = ref({
  title: '',
  content: ''
})

const userData = ref({
  id: '',
  baseUrl: '',
  apiKey: '',
  model: '',
})

onMounted(() => {
	// 获取用户配置
  store.getConfig()
})

const showToastFun = (config) => {
  if(!config.type) config.type = 'tishi'
  toastConfig.value = config
  showToast.value = true
  setTimeout(() => {
    showToast.value = false
  }, 3000)
}

const resetDeepseek = () => {
  store.userConfig.dsApiKey = '';
  store.userConfig.dsBaseUrl = '';
  store.userConfig.dsModel = '';
}

// 修改用户配置
const userUpdate = () => {
  store.updateConfig({dsApiKey: store.userConfig.dsApiKey,  dsModel: store.userConfig.dsModel}).then(() => {
    dialog.alert({ iconType: 'sc', message: '修改成功'}).then(() => {
      router.back()
    });
  })
}
</script>

<style lang="scss" scoped>
:deep(body) {
  background: #006CFF;
}
.set-page {
  padding: 22px 16px;
  box-sizing: border-box;
  width: 100%;
  flex: 1;
  border-radius: 20px 20px 0 0;
  background: #F6FAFF;
  position: relative;
  overflow-y: auto;
  
  &-title {
    font-family: PingFang SC, PingFang SC;
    font-weight: 600;
    font-size: 20px;
    color: #1A1A1A;
    margin-bottom: 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    .right {
      font-size: 14px;
      color: #006CFF;
    }
    
    .right.decoration {
      text-decoration-line: underline;
    }
  }
  
  &-items {
    width: 100%;
    background: #FFFFFF;
    border-radius: 10px;
    padding: 18px 20px;
    box-sizing: border-box;
    margin-bottom: 16px;
    
    .title {
      display: flex;
      // margin-bottom: 14px;
      .require {
        color: #FF3E3E;
        margin-right: 5px;
        font-weight: 600;
        font-size: 16px;
      }
      
      .text {
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 14px;
        color: #303E52;
      }
    }
    
    input {
      width: 100%;
      border-radius: 8px;
      font-family: PingFang SC, PingFang SC;
      font-size: 14px;
      color: #00042D;
      height: 49px;
      line-height: 49px;
      padding: 0 16px;
      background: #FFFFFF;
			box-sizing: border-box;
      border: 1px solid #DAE2EA;
    }
  }
  
  .button-block {
    padding: 0 16px;
		box-sizing: border-box;
    width: 100%;
    display: flex;
    justify-content: space-between;
    position: absolute;
    left: 0;
    bottom: 0;
    padding-bottom: 60px;
    
    button {
      width: 100%;
      height: 44px;
      text-align: center;
      border-radius: 22px;
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      font-size: 16px;
    }
    
    button:first-child {
      background: rgba(0,108,255,0.1);
      border: 1px solid #006CFF !important;
      color: #006CFF;
    }
    
    button:last-child {
      color: #ffffff;
      background: linear-gradient( 90deg, #006CFF 0%, #009FFF 100%);
    }
  }
}

input {
	transition: all 0.3s ease;
}
input:focus-within {
  border-color: #006cff;
  box-shadow: 0 0 0 2px rgba(0, 108, 255, 0.1);
  background: #fff;
}
</style>